package com.songlanyun.modules.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.drive.ValueObject;
import com.songlanyun.common.exception.RRException;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.exception.OrderException;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.order.dao.SaleServiceGoodsCardDao;
import com.songlanyun.modules.order.entity.SaleServiceGoodsCard;
import com.songlanyun.modules.order.service.SaleServiceGoodsCardService;


@Service("saleServiceGoodsCardService")
public class SaleServiceGoodsCardServiceImpl extends ServiceImpl<SaleServiceGoodsCardDao, SaleServiceGoodsCard> implements SaleServiceGoodsCardService {


    @Override
    public SaleServiceGoodsCard create(SaleServiceGoodsCard entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.insert(entity);
        return entity;
    }

    @Override
    public SaleServiceGoodsCard modify(SaleServiceGoodsCard entity) {
        ValidatorUtils.validateEntity(entity);
        this.baseMapper.updateById(entity);
        return entity;
    }

    @Override
    public void remove(Long id) {

    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        return null;
    }

    @Override
    public SaleServiceGoodsCard loadOrderIdAndChildOrder(Long orderId, Long childOrderId) {
        SaleServiceGoodsCard card = this.getOne(new LambdaQueryWrapper<SaleServiceGoodsCard>()
                .eq(SaleServiceGoodsCard::getOrderId, orderId)
                .eq(SaleServiceGoodsCard::getChildOrderId, childOrderId)
                .last("limit 1"));
        return card;
    }

    @Override
    public SaleServiceGoodsCard loadByCode(String verificationCode, boolean tw) {
        SaleServiceGoodsCard obj = this.getOne(new LambdaQueryWrapper<SaleServiceGoodsCard>()
                .eq(SaleServiceGoodsCard::getVerificationCode, verificationCode)
                .last("limit 1"));
        if(obj==null)
        {
            throw new RRException(OrderException.SERVICE_CARD_VERIFICATION_CODE_NOT_EXISTS);
        }
        return obj;
    }



}